//imports para trabajar con BBDD
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class GestorBD{

  //Constructor vacío.
  public GestorBD(){

  }

  public void modificar(String BD, String user, String pwd, String comanda) throws Exception{
    // This will load the MySQL driver, each DB has its own driver
    Class.forName("com.mysql.jdbc.Driver");
    // Setup the connection with the DB - Aquí hay que poner la BD, usuario y pwd definitivos.
    Connection connect = DriverManager.getConnection("jdbc:mysql://localhost/"+BD+"?"+"user="+user+"&password="+pwd); //ojo al pwd!
    PreparedStatement statement = connect.prepareStatement(comanda); statement.executeUpdate();
    
    connect.close();

  }
    //DEPRECAU!!
   public ResultSet leer(String BD, String user, String pwd, String comanda) throws Exception{
    // This will load the MySQL driver, each DB has its own driver
    Class.forName("com.mysql.jdbc.Driver");
    // Setup the connection with the DB - Aquí hay que poner la BD, usuario y pwd definitivos.
    Connection connect = DriverManager.getConnection("jdbc:mysql://localhost/"+BD+"?"+"user="+user+"&password="+pwd); //ojo al pwd!
    Statement statement = connect.createStatement();
    
    ResultSet res = statement.executeQuery(comanda);

    //statement.close();
    //connect.close(); //al cerrar el connect estoy cerrando el resulset??

    return res;

  }

}